package com.cya.forumproject.controller;

import com.cya.forumproject.common.AppResult;
import com.cya.forumproject.model.Board;
import com.cya.forumproject.services.IBoradService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：陈奕安（3048279304@qq.com）
 * @date ：Created in 2025/9/21 18:09
 * @description：
 * @modified By：
 * @version:
 */
@Slf4j
@Api(tags = "板块接口")//方法注解
@RestController
@RequestMapping("/board")
public class BoardController {

    @Value("${forum-project.index.board-num}")//从yml中获取信息
    private Integer indexBoardNum;

    @Resource
    private IBoradService boradService;

    /**
     * 查询首页板块
     * @return
     */
    @ApiOperation("获取首页板块列表")
    @GetMapping("/topList")
    public AppResult<List<Board>>  topList(){
        log.info("首页板块个数为："+indexBoardNum);

        List<Board> boards=boradService.selectByNum(indexBoardNum);
        if (boards==null){
            boards=new ArrayList<>();
        }
        return AppResult.success(boards);
    }
}